home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
parcs
/
parcs.lha
/
sample
/
queens.parcs
< prev
next >
Wrap
Text File
|
1992-06-08
|
1KB
|
35 lines
defdomain from1to4 int{1..4}.
defdomain from1to5 int{1..5}.
defdomain from1to6 int{1..6}.
defdomain from1to7 int{1..7}.
defdomain from1to8 int{1..8}.
defdomain from1to10 int{1..10}.
fourqueens([X1,X2,X3,X4]) :- from1to4(X1,X2,X3,X4),queens([X1,X2,X3,X4]).
fivequeens([X1,X2,X3,X4,X5]) :- from1to5(X1,X2,X3,X4,X5),queens([X1,X2,X3,X4,X5]).
sixqueens([X1,X2,X3,X4,X5,X6]) :- from1to6(X1,X2,X3,X4,X5,X6),queens([X1,X2,X3,X4,X5,X6]).
sevenqueens([X1,X2,X3,X4,X5,X6,X7]) :- from1to7(X1,X2,X3,X4,X5,X6,X7),
queens([X1,X2,X3,X4,X5,X6,X7]).
eightqueens([X1,X2,X3,X4,X5,X6,X7,X8]) :- from1to8(X1,X2,X3,X4,X5,X6,X7,X8),
queens([X1,X2,X3,X4,X5,X6,X7,X8]).
tenqueens([X1,X2,X3,X4,X5,X6,X7,X8,X9,X10]) :- from1to10(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10),
queens([X1,X2,X3,X4,X5,X6,X7,X8,X9,X10]).
noatack4([W,X,Y,Z]) :- W!=X+1,W!=X-1,W!=Y+2,W!=Y-2,W!=Z+3,W!=Z-3,
X!=Y+1,X!=Y-1,X!=Z+2,X!=Z-2,Y!=Z+1,Y!=Z-1.
queens([]).
queens([X|Y]) :- noattack(X,Y),queens(Y).
noattack(X,Y) :- noattacks(X,Y,1).
noattacks(X,[],N).
noattacks(X,[Y|Z],N) :- X!=Y,X!=Y+N,X!=Y-N,N2=N+1,noattacks(X,Z,N2).
perm4([W,X,Y,Z]) :- from1to4(W,X,Y,Z),W!=X,W!=Y,W!=Z,X!=Y,X!=Z,Y!=Z.
fourqueen([W,X,Y,Z]) :- noatack4([W,X,Y,Z]),perm4([W,X,Y,Z]).